using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.IOC.Context.Event.Attr;
using HCore.IOC.Context.Stereotype;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Support.CommandQuery;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.System.PlayerSystem;
using UnityEngine.SceneManagement;

namespace HCore.Tests.Runtime.ShootingEditor2D.Scripts.Command
{
    /// <summary>
    ///     碰撞玩家
    /// </summary>
    public class HurtPlayerCommand : ICommand
    {
        public HurtPlayerCommand(int hurt)
        {
            Hurt = hurt;
        }

        public int Hurt { get; }
    }

    [Component]
    public class HurtPlayerCommandHandler
    {
        [Autowired] private IPlayerModel mPlayerModel;

        [EventListener]
        private void ExecuteCommand(HurtPlayerCommand command)
        {
            mPlayerModel.Hp.Value -= command.Hurt;
            if (mPlayerModel.Hp.Value <= 0) SceneManager.LoadScene("Scenes/GameOver");
        }
    }
}